package com.ica.model.policy.time;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import com.ica.model.policy.time.utils.TimeUtils;
import com.ica.model.policy.time.utils.TimeUtils.DAYS;

public class TimeTableManager {
	
	/**
	 */
	private HashMap<DAYS, Vector<TimeStamp>> timeTable;
	
	public TimeTableManager() {	
		timeTable = new HashMap<DAYS,Vector<TimeStamp>>();
		for(DAYS day : DAYS.values()) {
			timeTable.put(day, new Vector<TimeStamp>());
		}
	}
	
	public boolean contains(Calendar time) {	
		if (timeTable.size()==0) return true;
		DAYS day = TimeUtils.calendarToDay(time);
		if (day==DAYS.UNKNOWN) return false;
		if (timeTable.get(day).size()==0) return true;
		boolean res = false;
		for(TimeStamp timeStamp : timeTable.get(day)) {
			boolean temp = timeStamp.contains(time);
			res = res || temp;
		}
		return res;
	}
	
	public List<TimeStamp> getTimeStamps(DAYS day) {		
		return timeTable.get(day);
	}
	
	public void addAllTimeStamp(DAYS day, List<TimeStamp> timeStamps) {	
		timeTable.get(day).addAll(timeStamps);
	}

	public void replaceAllTimeStamps(HashMap<DAYS, List<TimeStamp>> timeStamps) {
		timeTable.clear();
		for(DAYS day : DAYS.values()) {
			timeTable.put(day, new Vector<TimeStamp>(timeStamps.get(day)));
		}
	}
}
